package jp.aist.gtrc.plus.scheduler.job;


import java.util.Calendar;

import jp.aist.gtrc.plus.scheduler.status.JobStatus;
import jp.aist.gtrc.plus.scheduler.util.Checker;


public class WaitingTooLongJobChecker extends Checker<JobStatus>{

        public static final long DEFAULT_THRESHOLD =  30; // sec.
        
        private long threshold;

        public WaitingTooLongJobChecker() {
           this.threshold = DEFAULT_THRESHOLD;
        }

        public WaitingTooLongJobChecker(long t) {
           this.threshold = t;
        }

	public boolean isOK(JobStatus job){

		Calendar exe = job.getRequestedExecStartTime();
                if (exe == null) {
                   exe = job.getSubmitTime();
                }
		if (exe != null) {
			Calendar now = Calendar.getInstance();
			if ((now.getTimeInMillis()-exe.getTimeInMillis())/1000 > this.threshold) {
				return true;
			} else {
                                return false;
                        }
		}

		return true;

	}

}
